package com.ybkj.chat.ui.dialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.ybkj.chat.R;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author yyj
 * @create 2019-02-13 15:08
 * @Describe
 */
public class ImgTextDialog extends AlertDialog {

    ImageView ivType;
    TextView tvType;

    private Activity activity;
    private LayoutInflater inflater;
    private String textType;
    private int imgType;

    public ImgTextDialog(Activity activity, String textType, int imgType) {
        super(activity, THEME_TRADITIONAL);
        this.activity = activity;
        this.textType = textType;
        this.imgType = imgType;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
    }

    private void init() {
        View view = View.inflate(activity, R.layout.basic_dialog_img_text, null);
        setContentView(view);

        Window window = this.getWindow();
        window.setGravity(Gravity.CENTER);

        WindowManager.LayoutParams lp = window.getAttributes();
        DisplayMetrics d = activity.getResources().getDisplayMetrics();
        lp.width = (int) (d.widthPixels * 0.8);
        window.setAttributes(lp);
        ivType = view.findViewById(R.id.iv_type);
        tvType = view.findViewById(R.id.tv_type);

        ivType.setImageDrawable(activity.getResources().getDrawable(imgType));
        tvType.setText(textType);
    }

    @OnClick(R.id.btn_bind)
    public void onViewClicked() {
        dismiss();
    }
}
